﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TextEditor.TextDocument.Action
{
    public class A_Enter : A_Action
    {
        public A_Enter()
        {
            base.HotKey = System.Windows.Forms.Keys.Enter;
        }

        public override string ActionName()
        {
            return "onkeyenter";
        }

        public override bool Execute()
        {
            if (this.OwnerDocument.Content.CurrentElement != null)
            {
                ZYTextElement element = this.OwnerDocument.Content.CurrentElement;
                ZYTextInput input = null;
                if (element is ZYTextInput)
                {
                    input = (ZYTextInput)element;
                }
                else if (element.Parent != null && element.Parent is ZYTextInput)
                {
                    input = (ZYTextInput)element.Parent;
                }

                if (input != null)
                {
                    if (input.SelectType != "3")
                        input.ShowSelectKnow();
                    else if (input.Name != null && input.Name.Contains("时间") || input.Name.Contains("日期"))
                    {
                        base.OwnerDocument.Content.AutoClearSelection = true;
                        base.OwnerDocument.SetInputTime(input);
                    }
                }
            }
            return true;
        }

        public override bool isEnable()
        {
            ZYTextElement element = this.OwnerDocument.Content.CurrentElement;
            ZYTextInput input = null;
            if (this.OwnerDocument.Locked || element == null)
            {
                return false;
            }
            if (element is ZYTextInput)
            {
                input = (ZYTextInput)element;
            }
            else if (element.Parent != null && element.Parent is ZYTextInput)
            {
                input = (ZYTextInput)element.Parent;
            }
            return (base.myOwnerDocument.CanModify() && input != null && input.SelectType != "3") || (input != null && (input.Name != null && (input.Name.Contains("时间") || input.Name.Contains("日期"))));
        }

        public override bool CanHandleKeyDown()
        {
            return false;
        }
    }
}

